﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using CrystalDecisions.CrystalReports.Engine;
using System.IO;

using BLL;
using DAL;
using Models;
using System.Data;
using System.Text;
using System.Xml;
using Web.Old_App_Code;

public partial class backstage_points_for_order_list : System.Web.UI.Page
{
    // Fields
    protected AdminManager am = new AdminManager();
    protected string ds = "";
    protected string ed = "";
    protected string kw = "";
    protected PointsForOrderManager om = new PointsForOrderManager();
    protected string order = "id";
    protected string os = "";
    protected int ot = 0;
    protected int pageCount = 0;
    protected int pageIndex = 1;
    protected int pageSize = 20;
    protected PageList pl = new PageList();
    protected PageListManager plm = new PageListManager();
    protected string pss = "";
    protected string sd = "";
    protected int t = 0;
    protected int total = 0;

    // Methods
    protected void btnBulkModify_Click(object sender, EventArgs e)
    {
    }

    protected string GetDeliveryStatus(object deliveryStatus)
    {
        try
        {
            switch (Convert.ToInt32(deliveryStatus))
            {
                case 0:
                    return "未发货";

                case 1:
                    return "已发货";

                case 2:
                    return "已收货";
            }
        }
        catch
        {
        }
        return "";
    }

    protected string GetOrderStatus(object orderStatus)
    {
        try
        {
            switch (Convert.ToInt32(orderStatus))
            {
                case 0:
                    return "未确认";

                case 1:
                    return "已确认";

                case 2:
                    return "已取消";

                case 3:
                    return "无效";

                case 4:
                    return "退货";
            }
        }
        catch
        {
        }
        return "";
    }

    protected override object LoadPageStateFromPersistenceMedium()
    {
        byte[] inArray = ViewStateCompression.DeCompress(Convert.FromBase64String(base.Request.Form.Get("__MSPVSTATE")));
        LosFormatter formatter = new LosFormatter();
        return formatter.Deserialize(Convert.ToBase64String(inArray));
    }

    private void OrderBind()
    {
        try
        {
            if (base.Request.QueryString["p"] != null)
            {
                this.pageIndex = int.Parse(base.Request.QueryString["p"]);
            }
            if (base.Request.QueryString["ps"] != null)
            {
                this.pageSize = Convert.ToInt32(base.Request.QueryString["ps"]);
            }
            if (base.Request.QueryString["or"] != null)
            {
                this.order = base.Request.QueryString["or"];
            }
            if (base.Request.QueryString["ot"] != null)
            {
                this.ot = Convert.ToInt32(base.Request.QueryString["ot"]);
            }
            this.pl.TblName = "view_pointsForOrder";
            this.pl.StrGetFields = "id,orderNo,orderUser,userName,orderStatus,deliveryStatus,payStatus,Convert(nvarchar(10),createTime,121) as createTime,orderIntegral,goodsEntitys,amount,languageVersion";
            this.pl.FldName = this.order;
            this.pl.PageSize = this.pageSize;
            this.pl.PageIndex = this.pageIndex;
            this.pl.DoCount = 1;
            this.pl.OrderType = this.ot;
            if ((base.Request.QueryString["t"] != null) && (base.Request.QueryString["kw"] != null))
            {
                this.kw = base.Request.QueryString["kw"].Trim();
                this.pl.StrWhere = this.pl.StrWhere + ((this.pl.StrWhere != null) ? (" and " + base.Request.QueryString["t"] + " like '%" + this.kw + "%'") : (base.Request.QueryString["t"] + " like '%" + this.kw + "%'"));
            }
            if ((base.Request.QueryString["sd"] != null) && (base.Request.QueryString["ed"] != null))
            {
                this.sd = base.Request.QueryString["sd"];
                this.ed = base.Request.QueryString["ed"];
                this.pl.StrWhere = this.pl.StrWhere + ((this.pl.StrWhere != null) ? (" and createTime>='" + this.sd + " 00:00:00' and createTime<='" + this.ed + " 23:59:59'") : ("createTime>='" + this.sd + " 00:00:00' and createTime<='" + this.ed + " 23:59:59'"));
            }
            if (base.Request.QueryString["os"] != null)
            {
                this.os = base.Request.QueryString["os"];
                this.pl.StrWhere = this.pl.StrWhere + ((this.pl.StrWhere != null) ? (" and orderStatus=" + this.os) : ("orderStatus=" + this.os));
            }
            if (base.Request.QueryString["ds"] != null)
            {
                this.ds = base.Request.QueryString["ds"];
                this.pl.StrWhere = this.pl.StrWhere + ((this.pl.StrWhere != null) ? (" and deliveryStatus=" + this.ds) : ("deliveryStatus=" + this.ds));
            }
            if (base.Request.QueryString["pss"] != null)
            {
                this.pss = base.Request.QueryString["pss"];
                this.pl.StrWhere = this.pl.StrWhere + ((this.pl.StrWhere != null) ? (" and payStatus=" + this.pss) : ("deliveryStatus=" + this.pss));
            }
            this.pl.StrWhere = this.pl.StrWhere + ((this.pl.StrWhere == null) ? ("languageVersion='" + this.Session["language_version"].ToString() + "'") : (" and languageVersion='" + this.Session["language_version"].ToString() + "'"));
            this.total = Convert.ToInt32(this.plm.GetPageList(this.pl).Rows[0]["Total"]);
            this.pl.DoCount = 0;
            DataTable pageList = this.plm.GetPageList(this.pl);
            new PageListNo().DelPageSize(pageList, this.total);
            this.rptOrder.DataSource = pageList.DefaultView;
            this.rptOrder.DataBind();
        }
        catch
        {
        }
    }

    protected string OrderSumTotal()
    {
        int orderSumIntegralByTerm = 0;
        string term = "";
        try
        {
            if ((base.Request.QueryString["t"] != null) && (base.Request.QueryString["kw"] != null))
            {
                this.kw = base.Request.QueryString["kw"];
                term = base.Request.QueryString["t"] + " like '%" + this.kw + "%'";
            }
            if ((base.Request.QueryString["sd"] != null) && (base.Request.QueryString["ed"] != null))
            {
                this.sd = base.Request.QueryString["sd"];
                this.ed = base.Request.QueryString["ed"];
                term = term + ((term != "") ? (" and createTime>='" + this.sd + " 00:00:00' and createTime<='" + this.ed + " 23:59:59'") : ("createTime>='" + this.sd + " 00:00:00' and createTime<='" + this.ed + " 23:59:59'"));
            }
            if (base.Request.QueryString["os"] != null)
            {
                this.os = base.Request.QueryString["os"];
                term = term + ((term != "") ? (" and orderStatus=" + this.os) : ("orderStatus=" + this.os));
            }
            if (base.Request.QueryString["ds"] != null)
            {
                this.ds = base.Request.QueryString["ds"];
                term = term + ((term != "") ? (" and deliveryStatus=" + this.ds) : ("deliveryStatus=" + this.ds));
            }
            if (base.Request.QueryString["pss"] != null)
            {
                this.pss = base.Request.QueryString["pss"];
                term = term + ((term != "") ? (" and payStatus=" + this.pss) : ("deliveryStatus=" + this.pss));
            }
            term = term + ((term == "") ? ("languageVersion='" + this.Session["language_version"].ToString() + "'") : (" and languageVersion='" + this.Session["language_version"].ToString() + "'"));
            orderSumIntegralByTerm = this.om.GetOrderSumIntegralByTerm(term);
        }
        catch
        {
        }
        return ("订单总积分：" + orderSumIntegralByTerm);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if ((HttpContext.Current.Session["admin_user"] == null) && (HttpContext.Current.Session["language_version"] == null))
        {
            base.ClientScript.RegisterStartupScript(base.GetType(), "sJs", "top.location=\"login.html\";", true);
        }
        if (!base.IsPostBack)
        {
            if (base.Request.QueryString["t"] != null)
            {
                base.ClientScript.RegisterStartupScript(base.GetType(), "sa", "<script type=\"text/javascript\">selectIsExitItem(\"selectOrder\",\"" + base.Request.QueryString["t"] + "\");</script>");
            }
            if (base.Request.QueryString["ps"] != null)
            {
                base.ClientScript.RegisterStartupScript(base.GetType(), "sPs", "<script type=\"text/javascript\">selectIsExitItem(\"selectPageSize\",\"" + base.Request.QueryString["ps"] + "\");</script>");
            }
            if (base.Request.QueryString["os"] != null)
            {
                base.ClientScript.RegisterStartupScript(base.GetType(), "sOs", "<script type=\"text/javascript\">selectIsExitItem(\"selectOrderStatus\",\"os=" + base.Request.QueryString["os"] + "\");</script>");
            }
            if (base.Request.QueryString["ds"] != null)
            {
                base.ClientScript.RegisterStartupScript(base.GetType(), "sDs", "<script type=\"text/javascript\">selectIsExitItem(\"selectDeliveryStatus\",\"ds=" + base.Request.QueryString["ds"] + "\");</script>");
            }
            if (base.Request.QueryString["pss"] != null)
            {
                base.ClientScript.RegisterStartupScript(base.GetType(), "sPss", "<script type=\"text/javascript\">selectIsExitItem(\"selectPayStatus\",\"pss=" + base.Request.QueryString["pss"] + "\");</script>");
            }
            this.btnBulkModify.Attributes.Add("disabled", "disabled");
            this.OrderBind();
        }
    }

    protected override void SavePageStateToPersistenceMedium(object pViewState)
    {
        LosFormatter formatter = new LosFormatter();
        StringWriter output = new StringWriter();
        formatter.Serialize(output, pViewState);
        string hiddenFieldInitialValue = Convert.ToBase64String(ViewStateCompression.Compress(Convert.FromBase64String(output.ToString())));
        base.ClientScript.RegisterHiddenField("__MSPVSTATE", hiddenFieldInitialValue);
    }

}